package com.cennavi.mineplay.mineplay_data.model;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class DbNameInfo {

	private String dbname;
	
	/**
	 * 0 不变 1 变
	 */
	private int is_dynamic;
	
	/**
	 * 数据库名称前缀
	 */
	private String dbname_prefix;
	
	/**
	 * 0 每月一个库 1 不是每月一个库
	 */
	private int is_month;
	
	/**
	 * 0 每天一个库 1 不是每天一个库
	 */
	private int is_day;
	
	/**
	 * 0 一个月又进行拆分 1 不进行拆分
	 */
	private int is_month_split;
	
	/**
	 * 每月进行拆分的前缀
	 */
	private String month_prefix = "P";
	
	/**
	 * 按月进行拆分的个数
	 */
	private int num_per_month;

	public String getDbname() {
		return dbname;
	}

	public void setDbname(String dbname) {
		this.dbname = dbname;
	}

	public int getIs_dynamic() {
		return is_dynamic;
	}

	public void setIs_dynamic(int is_dynamic) {
		this.is_dynamic = is_dynamic;
	}

	public String getDbname_prefix() {
		return dbname_prefix;
	}

	public void setDbname_prefix(String dbname_prefix) {
		this.dbname_prefix = dbname_prefix;
	}

	public int getIs_month() {
		return is_month;
	}

	public void setIs_month(int is_month) {
		this.is_month = is_month;
	}

	public int getIs_day() {
		return is_day;
	}

	public void setIs_day(int is_day) {
		this.is_day = is_day;
	}

	public int getIs_month_split() {
		return is_month_split;
	}

	public void setIs_month_split(int is_month_split) {
		this.is_month_split = is_month_split;
	}

	public String getMonth_prefix() {
		return month_prefix;
	}

	public void setMonth_prefix(String month_prefix) {
		this.month_prefix = month_prefix;
	}

	public int getNum_per_month() {
		return num_per_month;
	}

	public void setNum_per_month(int num_per_month) {
		this.num_per_month = num_per_month;
	}
	
	
	public List<String> getDBName(){
		List<String> names = new ArrayList<String>();
		
		if (this.is_dynamic == 0)
		{
			names.add(this.dbname);
			
		}else{
			if (this.is_day == 0){
				
				Date date = new Date();
				
				SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
				
				String today = sdf.format(date);
				
				names.add(this.dbname_prefix+today);
				
			}else{
				
				Date date = new Date();
				
				SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
				
				String today = sdf.format(date);
				
				if (this.is_month_split == 1){
					names.add(this.dbname_prefix+today);
					
				}else{
					
					int vm = Integer.parseInt(new SimpleDateFormat("MM").format(date));
					
					vm = (vm - 1) / 10 + 1;
					
					if (vm > 3) vm = 3;
					
					//for(int i=1;i<=num_per_month;i++){
						names.add(this.dbname_prefix+today+this.month_prefix+vm);
					//}
					
					
				}
			}
		}
		
		return names;
	}
	
//	public static void main(String[] args) {
//		Date d = new Date();
//		
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
//		
//		System.out.println(sdf.format(d));
//		
//		
//	}
	
}
